<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子11-JS进阶（二）</title>
    </head>
    <body class="cols">
        <pre>
            <code>
                    // 例子11

                    var foo = {
                        name: 'joker',
                        showName: function() {
                          console.log(this.name);
                        }
                    }
                    var bar = {
                        name: 'rose'
                    }
                    foo.showName.call(bar); // rose
            </code>
        </pre>
        <pre>
            <code>
                    function exam(a, b, c, d, e) {

                        // 先看看函数的自带属性 arguments 什么是样子的
                        console.log(arguments); //

                        // 使用call/apply将arguments转换为数组,
                            // 返回结果为数组，arguments自身不会改变
                        var arg = [].slice.call(arguments);

                        console.log(arg);
                    }

                    exam(2, 8, 9, 10, 3);

                    // {0:2, 1:8, 2:9, 3:10, 4:3}
                    // [2, 8, 9, 10, 3]
            </code>
        </pre>
        <pre>
            <code>
                    // 定义父级的构造函数
                    var Person = function(name, age) {
                        this.name = name;
                        this.age  = age;
                        this.gender = ['man', 'woman'];
                    }

                    // 定义子类的构造函数
                    var Student = function(name, age, high) {

                        // use call
                        Person.call(this, name, age);
                        this.high = high;
                    }
                    Student.prototype.message = function() {
                        console.log('name:'+this.name+', age:'+this.age+', high:'+this.high+', gender:'+this.gender[0]+';');
                    }

                    new Student('xiaom', 12, '150cm').message();

                    // result
                    // ----------
                    // name:xiaom, age:12, high:150cm, gender:man;
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/11.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>